package com.fan.txl.ui.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import com.base.txl.activity.SuperActivity;
import com.base.txl.dialog.LoadingDialog;
import com.f2prateek.rx.preferences2.RxSharedPreferences;
import com.fan.txl.data.loading.Loading;
import com.fan.txl.di.component.APIComponent;
import com.fan.txl.di.component.ApplicationComponent;
import com.fan.txl.di.component.DaggerAPIComponent;
import com.fan.txl.di.component.DaggerApplicationComponent;
import com.fan.txl.di.module.APIModule;
import com.fan.txl.di.module.ApplicationModule;
import com.fan.txl.di.module.NetModule;
import com.fan.txl.mock.api.service.APIService;
import com.fan.txl.mock.api.service.LoadAPIData;
import com.fan.txl.mock.api.service.mock.MockAPIService;
import com.fan.txl.pay.PayInterface;
import com.tencent.mm.sdk.openapi.IWXAPI;
import javax.inject.Inject;
import retrofit2.mock.BehaviorDelegate;


/**
 * Created by jiajiabao on 17-1-10.
 */

public abstract class BaseActivity extends SuperActivity implements LoadingDialog {


    @Inject
    APIService mAPIService;

    @Inject
    MockAPIService mMockAPIService;

    @Inject
     RxSharedPreferences mRxSharedPreferences;

    @Inject
    PayInterface payInterface;

    @Inject
    IWXAPI iwxApi;

    public Loading mLoading=new Loading();

    public APIService getAPIService() {
        return mAPIService;
    }

    public MockAPIService getMockAPIService() {
        return mMockAPIService;
    }

    public RxSharedPreferences getRxSharedPreferences() {
        return mRxSharedPreferences;
    }

    public PayInterface getPayInterface() {
        return payInterface;
    }


    public IWXAPI getWxApi() {
        return iwxApi;
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        createAPIComponent().inject(this);

    }



    protected APIComponent createAPIComponent(){
      return  DaggerAPIComponent
                .builder()
                .netModule(new NetModule())
                .aPIModule(new APIModule())
                .applicationComponent(createAppComponent())
                .build();
    }



    protected ApplicationComponent createAppComponent(){
        ApplicationComponent applicationComponent= DaggerApplicationComponent.builder().applicationModule(new ApplicationModule(getApplication())).build();
        return  applicationComponent;
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (this instanceof LoadAPIData){
            LoadAPIData loadAPIData =(LoadAPIData)this;
            loadAPIData.loadData();
        }
    }
    // compile 'com.github.z-chu:RxCache:1.0'

  /*  RxCache  rxCache = new RxCache.Builder()
            .appVersion(1)//不设置，默认为1
    .diskDir(new File(getCacheDir().getPath() + File.separator + "data-cache"))
            .diskConverter(new SerializableDiskConverter())//目前只支持Serializable缓存
            .memoryMax(2*1024*1024)//不设置,默认为运行内存的8分之1
    .diskMax(20*1024*1024)//不设置， 默认为50MB
    .build();*/

    @Override
    public void onShow() {
        mLoading.setShowing(true);
    }

    @Override
    public void onHide() {
        mLoading.setShowing(false);
    }
}
